from django.contrib.auth.models import User
from django.db import models

# Create your models here.

#商品类型
class CommodityCategory(models.Model):
    category_name = models.CharField(max_length=50)

#商品表
class Commodity(models.Model):
    commodity_no = models.CharField(max_length=100)
    stock = models.IntegerField(verbose_name='库存量',default=0)
    category_id = models.ForeignKey(CommodityCategory,on_delete=models.CASCADE)
    cover = models.ImageField(max_length=200,default='',upload_to='commpdity/cover/')
    price = models.DecimalField(max_digits=10,decimal_places=2)

#订单表
class UserOrder(models.Model):
    order_no = models.CharField(max_length=1000)
    user = models.ForeignKey(User,on_delete=models.CASCADE)
    commodity_no = models.CharField(max_length=100)
    buy_count = models.PositiveIntegerField(default=1)
    pay_money = models.DecimalField(max_digits=18,decimal_places=2)
    pay_time = models.DateTimeField(auto_now=True)
    choices = (
        (0, '未中奖'),
        (1, '中奖')
    )
    is_good = models.PositiveSmallIntegerField(choices=choices,default=1)
    choices =(
        (0,'未支付'),
        (1,'已支付')
    )
    is_pay = models.PositiveSmallIntegerField(choices==choices,default=0)
    add_time = models.DateTimeField(auto_now_add=True)
    choices=(
        (0,'否'),
        (1,'是')
    )
    is_random = models.PositiveSmallIntegerField(choices=choices,default=0,verbose_name='是否转盘订单')
